home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 3
/
Aminet 3 - July 1994.iso
/
Aminet
/
mus
/
misc
/
copyist.lha
/
txt2c.c
< prev
Wrap
C/C++ Source or Header
|
1994-01-10
|
1KB
|
87 lines
#include "vd0:stdio.h"
#define BUF_SIZE 32
char s[16];
char *t_pos=0;
char token[16];
int copyist[3];
FILE *fpin,*fpout;
main(argc,argv)
int argc;
char *argv[];
{
if((fpin=fopen(argv[1],"r"))==0) {
printf("Cannot open file %s\n",argv[1]);
exit(0);
}
if((fpout=fopen(argv[2],"w"))==0) {
printf("Cannot open file %s\n",argv[2]);
exit(0);
}
while (fgets(s,13,fpin))
{
t_pos = s;
numconvert();
WriteCopyist();
}
WriteEndFile();
fclose(fpin);
fclose(fpout);
}
numconvert()
{
int x;
get_token();
copyist[0] = atoi(token);
get_token();
copyist[1] = atoi(token);
get_token();
copyist[2] = atoi(token);
}
get_token()
{
char *p;
p=token;
while(*t_pos==' ') t_pos++;
if(*t_pos=='\0') {
*p++='\0';
*p='\0';
return;
}
while(*t_pos!=' ' && *t_pos!='\0') {
*p=*t_pos++;
p++;
}
*p='\0';
}
WriteCopyist()
{
short x,y,z;
int total,xpos,ypos;
xpos = copyist[0];
ypos = copyist[1];
z = copyist[2];
total = 3200 + ((xpos-1) + ((ypos-1) * 160));
x = total / 256;
y = total - (x * 256);
fprintf(fpout,"%c",x);
fprintf(fpout,"%c",y);
fprintf(fpout,"%c",z);
}
WriteEndFile()
{
fprintf(fpout,"%c",255);
fprintf(fpout,"%c",255);
fprintf(fpout,"%c",255);
fprintf(fpout,"%c",255);
fprintf(fpout,"%c",255);
fprintf(fpout,"%c",255);
}